package com.favccxx.search.infrastructure.util.rest;

public class RestResult<T> {

    public static final int SUCCESS = 0;

    public static final String SUCCESS_MSG = "Operate success.";

    public static String getSuccessMsg() {
        return SUCCESS_MSG;
    }

    public static final int ERROR = 1;

    int code;

    String message;

    T data;

    public RestResult(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public RestResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public RestResult() {

    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> RestResult<T> sucess() {
        return new RestResult<T>(SUCCESS, SUCCESS_MSG, null);
    }

    public static <T> RestResult<T> sucess(T data) {
        return new RestResult<T>(SUCCESS, SUCCESS_MSG, data);
    }

    public static <T> RestResult<T> sucess(int code, String message) {
        return new RestResult<T>(SUCCESS, message);
    }

    public static <T> RestResult<T> sucess(T data, String message) {
        return new RestResult<T>(SUCCESS, message, data);
    }

    public static <T> RestResult<T> sucess(int code, T data, String message) {
        return new RestResult<T>(SUCCESS, message, data);
    }

    public static <T> RestResult<T> error(int code, String message) {
        return new RestResult<T>(code, message);
    }

    public static <T> RestResult<T> invalidParams(String message) {
        return new RestResult<T>(4001, message);
    }

    public static <T> RestResult<T> lackParams(String message) {
        return new RestResult<T>(4002, message);
    }


}
